﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ITPCTaxFormModel;
using System.Text;

public partial class tmp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        using (var context = new ITPCTaxFormEntities())
        {
            var pro_data = context.Product.Select(p => new { p.ProductID, p.ProductCode, p.Description }).ToList();
            var procate_data = context.ProductCategory.Select(pc => new { pc.ProductCategoryID, pc.ProductCategoryCode, pc.Description });

            var display = new List<Product>();
            foreach (var i in pro_data)
                display.Add(new Product { 
                                ProductID = i.ProductID.ToString(), 
                                ProductCategoryID ="", 
                                ProductCode = i.ProductCode.ToString(), 
                                ProductCategoryCode="", 
                                SearchString = i.ProductCode.ToString() + " - " + i.Description.ToString() 
                                }
                            );
            foreach (var i in procate_data)
                display.Add(new Product { 
                                ProductID="", 
                                ProductCategoryID = i.ProductCategoryID.ToString(), 
                                ProductCode="", 
                                ProductCategoryCode = i.ProductCategoryCode.ToString(), 
                                SearchString = i.ProductCategoryCode.ToString() + " - " + i.Description.ToString() 
                                }
                           );

            var sb = new StringBuilder();
            var query = display.OrderBy(d => d.SearchString).ToList();

            //Display on UserInput TextBox
            foreach (var q in query)
                sb.AppendFormat("{0}{1}|{2}|{3}|{4}|{5}", (sb.Length > 0 ? "\n" : ""), q.SearchString, q.ProductID, q.ProductCategoryID, q.ProductCode, q.ProductCategoryCode);

            txtTmp.InnerText = sb.ToString();
         }

    }

    
}